package com.hanbang.gycatering.comeon;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.hanbang.gangyu.R;
import com.hanbang.gycatering.application.MyApplication;
import com.hanbang.gycatering.utils.HttpInterfaces;
import com.hanbang.gycatering.utils.MyRequestCallBack;
import com.hanbang.gycatering.utils.MyToast;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class DealActivity extends Activity {

	private TextView texttitle;
	private WebView vebView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.deal);

		((TextView) findViewById(R.id.top_bar_title)).setText("注册协议");
		ImageView iv = (ImageView) findViewById(R.id.top_bar_left_image);
		iv.setVisibility(View.VISIBLE);
		iv.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		vebView = (WebView) findViewById(R.id.deal_text);
		texttitle = (TextView) findViewById(R.id.deal_title);
		getDealData();
	}
	private void getDealData() {
		// TODO Auto-generated method stub
		((MyApplication) getApplicationContext()).httpUtils.send(
				HttpMethod.GET, HttpInterfaces.talk,
				new MyRequestCallBack<String>(DealActivity.this,
						getString(R.string.loadding)) {
					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						super.onSuccess(responseInfo);
						try {
							JSONObject json = new JSONObject(
									responseInfo.result);
							if (json.getInt("state") == 1) {
								String webtext = json.getString("content");
								vebView.loadDataWithBaseURL(null, webtext, "text/html",
										"utf-8", null);
							} else {
								MyToast.show(DealActivity.this, "获取数据失败",
										Toast.LENGTH_SHORT);
							}
						} catch (JSONException e) {
							e.printStackTrace();
							MyToast.show(DealActivity.this, "获取数据失败",
									Toast.LENGTH_SHORT);
						}
					}
				});
	}
}
